package com.lkd.shoppingcart.entity;

import java.math.BigDecimal;
import java.util.List;

/**
 * 购物车
 * @author shubing
 *
 */
public class Cart {

	private List<CartItemView> items;

	public Cart() {
		super();
	}
	
	public Cart(List<CartItemView> items) {
		super();
		this.items = items;
	}

	public List<CartItemView> getItems() {
		return items;
	}

	public void setItems(List<CartItemView> items) {
		this.items = items;
	}
	
	/**
	 * 获取所属用户编号
	 * @return 返回所属用户编号
	 */
	public int getUserId() {
		int userId = 0;
		for (CartItemView cartItemView : items) {
			userId = cartItemView.getUserId();
			break;
		}
		return userId;
	}
	
	/**
	 * 获取购物车商品总数
	 * @return 返回购物车商品总数
	 */
	public int getTotalCount() {
		int totalCount = 0;
		for (CartItemView cartItemView : items) {
			totalCount += cartItemView.getQuantity();
		}
		return totalCount;
	}
	
	/**
	 * 获取购物车商品总金额
	 * @return 返回购物车商品总金额
	 */
	public BigDecimal getTotalPrice() {
		BigDecimal totalPrice = new BigDecimal(0);
		for (CartItemView cartItemView : items) {
			BigDecimal quantity = new BigDecimal(cartItemView.getQuantity());
			totalPrice = totalPrice.add(cartItemView.getPrice().multiply(quantity));
		}
		return totalPrice;
	}
	
}
